<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
cfc('core')->checklogin();
$return['role']=$_SESSION['role'];
$return['member']=array();
if($_RQ['op']=='list'){
	$member=pdo_get('jy_fuwu_worker',array('mid'=>$_SESSION['uid']));
	if(!$member){
		exi('您还不是'.$this->wname.'！','error','/home/');
	}else{
		$member['user']='worker';
	}
	$params['status']=$_RQ['status']?:1;
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid'],'worker_id'=>$member['id']);
    $fields=array('id','ordersn','lat','end_lat','serve_id','name','mobile','worker_id','mid','createtime','onstart_time','oncar_time','onend_time','pay_time','status','price','price1','start_seat','dest_seat','cuid');
    $orderby='createtime desc';
	$total='';
	$return['list']=pdo_getslice('jy_fuwu_order',$params,array($pindex,$psize),$total,$fields,'',$orderby);	
	if($return['list']){
		foreach($return['list'] as &$v){
			if($v['cuid'] && $v['cuid']!=$_SESSION['uid']){
				$v['cel']=1;
			}
			$v['createtime']=date('Y-m-d H:i:s',$v['createtime']);
			$v['onstart_time']=$v['onstart_time']?date('Y-m-d H:i:s',$v['onstart_time']):0;
			$v['oncar_time']=$v['oncar_time']?date('Y-m-d H:i:s',$v['oncar_time']):0;
			$v['onend_time']=$v['onend_time']?date('Y-m-d H:i:s',$v['onend_time']):0;
			$v['pay_time']=$v['pay_time']?date('Y-m-d H:i:s',$v['pay_time']):0;
			$v['lat']=json_decode($v['lat']);
			$v['end_lat']=$v['end_lat']?json_decode($v['end_lat']):array();
			if($v['status']==1 || $v['status']==6){
				$v['close_end']=$return['pluginset']['close_end'];
				$v['close_fee']=$return['pluginset']['close_fee'];
			}
			$v['serve']=pdo_get('jy_fuwu_serve',array('id'=>$v['serve_id']));
		}
	}
	$return['type']=$this->order_status;
	$return['user']=$member['user'];
	$return['status']=1;
	$return['post']=array('baobeitype'=>1);
	$return['params']=array('status'=>$_RQ['status']?:1);
	exi($return);
}
if($_RQ['op']=='del'){
	$id=intval($_RQ['id']);
	if($id){
		$order=pdo_get('jy_fuwu_order',array('id'=>$id));
		
		pdo_delete('jy_fuwu_order',array('id'=>$id));	
	}
	
	exi('删除成功！','','jy_fuwu/worker_order/list/');

}
if($_RQ['op']=='cel'){
	$id=intval($_RQ['id']);	
	if($id){
		$order=pdo_get('jy_fuwu_order',array('id'=>$id));
		if($order['status']==1){
			pdo_update('jy_fuwu_order',array('status'=>2,'cuid'=>$_SESSION['uid']),array('id'=>$id));	
		}else{
			pdo_update('jy_fuwu_order',array('status'=>3,'cuid'=>$_SESSION['uid']),array('id'=>$id));	
		}
		pdo_update('jy_fuwu_worker',array('busy'=>1),array('id'=>$order['worker_id']));
	}	
	exi('已申请取消,请联系对方确认','','jy_fuwu/worker_order/list/');
}
if($_RQ['op']=='baobei'){
	$id=intval($_RQ['id']);	
	$post=get_postdata();
	if($id){
		$order=pdo_get('jy_fuwu_order',array('id'=>$id));
		if($order['status']==1){
			pdo_update('jy_fuwu_order',array('status'=>2,'cuid'=>$_SESSION['uid']),array('id'=>$id));	
		}else{
			pdo_update('jy_fuwu_order',array('status'=>3,'cuid'=>$_SESSION['uid']),array('id'=>$id));	
		}
		pdo_update('jy_fuwu_worker',array('busy'=>1),array('id'=>$order['worker_id']));
		$msg=$this->baobei_types[$post['baobeitype']];
		model('jy_fuwu/order')->add_baobei($id,$msg,$order['status']);
	}
	exi('报备成功！','','jy_fuwu/worker_order/list/');
}
if($_RQ['op']=='dcel'){
	$id=intval($_RQ['id']);
	if($id){
		$this->model('order')->order_cancel($id);
	}
	exi('已确定取消','','jy_fuwu/worker_order/list/');
}
if($_RQ['op']=='detail'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择订单','error','jy_fuwu/worker_order/list/');
	}	
	$return['item']=pdo_get('jy_fuwu_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	$return['item']['createtime']=date('Y-m-d H:i:s',$return['item']['createtime']);
	exi($return);
}
if($_RQ['op']=='onstart'){
	$id=intval($_RQ['id']);	
	pdo_update('jy_fuwu_order',array('status'=>7,'onstart_time'=>TIMESTAMP),array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));	
	exi('更新订单成功！','','jy_fuwu/worker_order/list/');
}
if($_RQ['op']=='oncar'){
	$id=intval($_RQ['id']);	
	pdo_update('jy_fuwu_order',array('status'=>8,'oncar_time'=>TIMESTAMP),array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));	
	exi('更新订单成功！','','jy_fuwu/worker_order/list/');
}
if($_RQ['op']=='onend'){
	$id=intval($_RQ['id']);	
	$sendpay=intval($_RQ['sendpay']);	
	pdo_update('jy_fuwu_order',array('status'=>9,'onend_time'=>TIMESTAMP),array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));	
	if($sendpay){
		$this->model('notice')->notice_nopay2buyer($id);
	}else{
		pdo_update('jy_fuwu_order',array('ispay'=>1,'pay_time'=>TIMESTAMP),array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));	
	}
	$this->model('order')->change_fee($id);
	exi('更新订单成功！','','jy_fuwu/worker_order/list/');
}
if($_RQ['op']=='stoprecorder'){
	$post=get_postdata();
	$worker_id=pdo_getcolumn('jy_fuwu_worker',array('mid'=>$_SESSION['uid']),'id');
	$log=array(
			'uniacid'=>$_SESSION['uniacid'],
			'orderid'=>intval($post['orderid']),
			'mid'=>$_SESSION['uid'],
			'file'=>$post['res']['audio'],
			'duration'=>$post['res']['duration'],
			'filesize'=>$post['res']['fileSize'],
			'worker_id'=>$worker_id,
	);
	$log['createtime']=TIMESTAMP;
	pdo_insert('jy_fuwu_order_audiolog',$log);
	$orderid=pdo_insertid();	
	exi('保存录音成功！');
}
?>